<template>
  <div>
    <h1>这是登录页面</h1>
    <el-form ref="form" :model="form" label-width="80px">
      <el-form-item label="用户名">
        <el-input v-model="form.username"></el-input>
      </el-form-item>
      <el-form-item label="密码">
        <el-input v-model="form.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="login()">登录</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { userlogin } from "@/api/userApi";
export default {
  data() {
    return {
      form: {
        username: "",
        password: "",
      },
    };
  },
  methods: {
    login() {
      userlogin(this.form).then((res) => {
        if (res.data.flag) {
          this.$message.success("登录成功");
          console.log(res.data.data);
          window.sessionStorage.setItem("token", res.data.data);
          this.$router.push("/list");
        } else {
          this.$message.error("登录失败");
        }
      });
    },
  },
};
</script>

<style scoped></style>
